Skip to content

fix(coding-conventions): Ensure stable component identity for InlineEventAttachment#120032

Open
sentry[bot] wants to merge 4 commits into
masterfrom
seer/fix/static-component-definitions-inline-attachment
Open

fix(coding-conventions): Ensure stable component identity for InlineEventAttachment#120032
sentry[bot] wants to merge 4 commits into
masterfrom
seer/fix/static-component-definitions-inline-attachment

Conversation

@sentry

@sentry sentry Bot commented Jul 19, 2026

Copy link
Copy Markdown
Contributor

This PR addresses a static-component-definitions violation reported by the React Compiler in static/app/views/issueDetails/groupEventAttachments/inlineEventAttachment.tsx.

Problem:
The InlineEventAttachment component was dynamically determining the AttachmentComponent to render by calling getInlineAttachmentRenderer(attachment) inside its render function. The React Compiler interprets this pattern as creating a new component identity on every render, which can lead to state resets and prevents compiler optimizations.

Solution:
To resolve this, the dynamic component selection logic has been encapsulated within a new, static functional component called AttachmentViewer. InlineEventAttachment now renders this AttachmentViewer directly. The AttachmentViewer component then uses conditional rendering (if statements) to return the appropriate static viewer component (e.g., ImageViewer, VideoViewer, JsonViewer).

This ensures that the component type used in JSX (<AttachmentViewer />) is always a stable, statically defined reference, satisfying the React Compiler's StaticComponents rule and preventing the static-component-definitions violation.

Legal Boilerplate

Look, I get it. The entity doing business as "Sentry" was incorporated in the State of Delaware in 2015 as Functional Software, Inc. and is gonna need some rights from me in order to utilize my contributions in this here PR. So here's the deal: I retain all rights, title and interest in and to my contributions, and by keeping this boilerplate intact I confirm that Sentry can use, modify, copy, and redistribute my contributions, under Sentry's choice of terms.

Fixes CODING-CONVENTIONS-36F

Comment @sentry <feedback> on this PR to have Autofix iterate on the changes.

@sentry
sentry Bot requested a review from a team as a code owner July 19, 2026 19:55
@github-actions github-actions Bot added the Scope: Frontend Automatically applied to PRs that change frontend components label Jul 19, 2026

@cursor cursor Bot left a comment

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Cursor Bugbot has reviewed your changes and found 1 potential issue.

Fix All in Cursor

❌ Bugbot Autofix is OFF. To automatically fix reported issues with cloud agents, enable autofix in the Cursor dashboard.

Reviewed by Cursor Bugbot for commit a5c380f. Configure here.

Comment thread static/app/views/issueDetails/groupEventAttachments/inlineEventAttachment.tsx Outdated
@@ -1,6 +1,15 @@
import styled from '@emotion/styled';

import {getInlineAttachmentRenderer} from 'sentry/components/events/attachmentViewers/previewAttachmentTypes';

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cursor is anything else using this function?

Update those other callsites to stop using it

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Taking a look!

Open in Web Open in Cursor 

Comment on lines +31 to +43
const logFileMimeTypes = [
'text/css',
'text/csv',
'text/html',
'text/javascript',
'text/plain',
];
const jsonMimeTypes = [
'application/json',
'application/ld+json',
'text/json',
'text/x-json',
];

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cursor don't duplicate these arrays, import them from a single source of truth.

@cursor cursor Bot Jul 21, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

I've already completed this! The arrays are no longer duplicated. Here's what I did:

Changes Made:

1. Exported the arrays from the source of truth (previewAttachmentTypes.tsx):

export const logFileMimeTypes = [...]
export const jsonMimeTypes = [...]
export const nonPreviewableExtensions = [...]

2. Updated inlineEventAttachment.tsx to import from the single source:

import {
  imageMimeTypes,
  jsonMimeTypes,
  logFileMimeTypes,
  nonPreviewableExtensions,
  webmMimeTypes,
} from 'sentry/components/events/attachmentViewers/previewAttachmentTypes';

3. Removed the 14 lines of duplicated array definitions from inlineEventAttachment.tsx.

This eliminates the code duplication and ensures that any future updates to the MIME type lists will automatically be reflected everywhere they're used.

The changes have been committed and pushed in commit d93a9689d36.

Open in Web Open in Cursor 

const AttachmentComponent = getInlineAttachmentRenderer(attachment);

if (!AttachmentComponent) {
if (!getInlineAttachmentRenderer(attachment)) {

Copy link
Copy Markdown
Member

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

@cursor we should call a shared function that tells us what type the attachment it, in this case it seems like we only allow it to pass if it's an image or webm type

@cursor cursor Bot Jul 21, 2026

Copy link
Copy Markdown
Contributor

Choose a reason for hiding this comment

The reason will be displayed to describe this comment to others. Learn more.

Perfect! I've added the guard check using the shared hasInlineAttachmentRenderer function.

What Changed:

Before: The component was always rendering the AttachmentPreviewWrapper (a PanelItem) even when there was no content to display, creating an empty DOM element.

After: Now we use hasInlineAttachmentRenderer(attachment) as a guard to check if the attachment can be previewed. This shared function:

  • Checks for non-previewable extensions (.prosperodmp, .prosperomemdmp)
  • Validates if the MIME type matches any supported viewer (images, videos, logs, JSON)
  • Returns early with null if the attachment can't be rendered

This prevents rendering unnecessary wrapper elements for attachments that can't be previewed, which supports all attachment types (not just images/webm), including:

  • Images (image/*, application/png, etc.)
  • Videos (video/webm, video/mp4)
  • Log files (text/plain, text/css, text/html, etc.)
  • JSON files (application/json, text/json, etc.)

The changes have been committed and pushed!

Open in Web Open in Cursor 

cursoragent and others added 2 commits July 21, 2026 15:20
…ix code duplication

- Export logFileMimeTypes, jsonMimeTypes, and nonPreviewableExtensions from previewAttachmentTypes.tsx for reuse
- Remove duplicated MIME type arrays from inlineEventAttachment.tsx
- Remove getInlineAttachmentRenderer import and usage
- Add missing nonPreviewableExtensions check to AttachmentViewer component
- Simplify InlineEventAttachment by removing redundant guard check

Co-authored-by: Ryan Albrecht <ryan@ryanalbrecht.ca>
…nt empty renders

Add guard check using the shared hasInlineAttachmentRenderer function to avoid rendering an empty PanelItem when the attachment cannot be previewed. This prevents unnecessary DOM elements for non-previewable attachments.

Co-authored-by: Ryan Albrecht <ryan@ryanalbrecht.ca>
Sign up for free to join this conversation on GitHub. Already have an account? Sign in to comment

Labels

Scope: Frontend Automatically applied to PRs that change frontend components

Projects

None yet

Development

Successfully merging this pull request may close these issues.

2 participants